import { defineConfig, loadEnv } from 'vite'
import vueJsx from '@vitejs/plugin-vue-jsx';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import UnoCSS from 'unocss/vite'
import { resolve } from 'path';

export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), '')

  return {
    plugins: [
      vue(),
      vueJsx(),
      UnoCSS()
    ],
    resolve: {
      alias: {
        '@img': resolve(__dirname, 'src/assets/image'), // 图片路径别名
        '@': resolve(__dirname, 'src/') // 根路徑
      },
      extensions: ['.js', '.json', '.ts', '.tsx', '.jsx'] // 使用路径别名时想要省略的后缀名，可以自己 增减
    },
    build: {
      cssCodeSplit: true,
    },
    css: {
      postcss: {},
      requireModuleExtension: true,
      preprocessorOptions: {
        scss: {
          additionalData: `@import "@/theme.scss";`
        }
      }
    },
    server: {
      host: true,
      proxy: {
        '/api': {
          target: 'https://httpbin.org/',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        }
      }
    }

  }
})